﻿package mortal.game.view.mount.panel
{
    import com.greensock.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import flash.text.*;
    import flash.utils.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.component.window.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.mount.data.*;
    import mortal.mvc.interfaces.*;

    public class BlessClearWin extends SmallWindow
    {
        private var _blessData:BlessData;
        private var _leftTime:SecTimerView;
        private var _desc:GTextFiled;
        private var _txt:GTextFiled;
        private var _btnOK:GButton;
        private var _btnCancel:GButton;
        private var _expBar:BaseProgressBar;
        private var _callBack:Function;
        public var _clickBtnType:int = 0;
        public static var winOpenRecortDic:Dictionary = new Dictionary();
        private static var _instance:BlessClearWin;
        public static const BlessBtnTypeOk:int = 1;
        public static const BlessBtnTypeCacel:int = 2;

        public function BlessClearWin(param1:ILayer = null)
        {
            super(param1);
            this.layer = LayerManager.alertLayer;
            this.title = Language.getString(35433);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            var _loc_1:* = GlobalStyle.textFormatChen;
            _loc_1.size = 13;
            _loc_1.bold = true;
            this._txt = UIFactory.gTextField("", 50, 80, 150, 22, this, GlobalStyle.textFormatlan);
            this._desc = UIFactory.gTextField("", 23, 110, 255, 180, this, GlobalStyle.textFormatBai, true);
            this._desc.autoSize = TextFieldAutoSize.LEFT;
            this._expBar = UICompomentPool.getUICompoment(BaseProgressBar);
            this._expBar.x = 20;
            this._expBar.y = 50;
            this._expBar.setBg(ImagesConst.MountBarBg, true, 291, 13);
            this._expBar.setProgress(ImagesConst.MountBar, false, 4, 4, 283, 13);
            this._expBar.setLabel(BaseProgressBar.ProgressBarTextOnlyShowValue, 45);
            this._expBar.isOverShowValue = true;
            this._expBar.mouseChildren = false;
            this._expBar.mouseEnabled = true;
            this.addChild(this._expBar);
            _loc_1 = GlobalStyle.textFormatHong;
            this._leftTime = new SecTimerView();
            this._leftTime.width = 35;
            this._leftTime.autoSize = TextFieldAutoSize.LEFT;
            this._leftTime.mouseEnabled = false;
            this._leftTime.defaultTextFormat = _loc_1;
            this._leftTime.filters = [FilterConst.glowFilter];
            this._leftTime.setParse(Language.getString(30055));
            this._leftTime.configEventListener(EventName.SecViewTimeChange, this.onSecViewTimeChangeHandler);
            this._leftTime.x = 200;
            this._leftTime.y = 80;
            this.addChild(this._leftTime);
            this._btnOK = UIFactory.gButton(Language.getString(35434), 40, 0, 100, 25, this);
            this._btnOK.configEventListener(MouseEvent.CLICK, this.clickHandler);
            this._btnCancel = UIFactory.gButton(Language.getString(35435), 217, 0, 75, 25, this);
            this._btnCancel.configEventListener(MouseEvent.CLICK, this.clickHandler);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._txt.dispose(param1);
            this._txt = null;
            this._desc.dispose(param1);
            this._desc = null;
            this._leftTime.dispose(param1);
            this._leftTime = null;
            this._btnOK.dispose(param1);
            this._btnOK = null;
            this._btnCancel.dispose(param1);
            this._btnCancel = null;
            this._expBar.dispose(param1);
            this._expBar = null;
            this._callBack = null;
            this._blessData = null;
            this._clickBtnType = 0;
            super.disposeImpl(param1);
            return;
        }// end function

        private function clickHandler(event:MouseEvent) : void
        {
            switch(event.currentTarget)
            {
                case this._btnOK:
                {
                    this._clickBtnType = BlessBtnTypeOk;
                    break;
                }
                case this._btnCancel:
                {
                    this._clickBtnType = BlessBtnTypeCacel;
                    winOpenRecortDic[this._blessData.type] = true;
                    break;
                }
                default:
                {
                    break;
                }
            }
            this.hide();
            return;
        }// end function

        override public function hide() : void
        {
            if (this._callBack != null)
            {
                this._callBack.apply(null, [this._clickBtnType == 0 ? (BlessBtnTypeOk) : (this._clickBtnType)]);
            }
            super.hide();
            return;
        }// end function

        public function set callBack(param1:Function) : void
        {
            this._callBack = param1;
            return;
        }// end function

        public function set blessData(param1:BlessData) : void
        {
            this._blessData = param1 as BlessData;
            var _loc_2:* = Language.getStringByParam(35437, this._blessData.type, this._blessData.type, this._blessData.type, this._blessData.type);
            this._desc.htmlText = _loc_2;
            this._txt.text = Language.getStringByParam(35436, this._blessData.type);
            this._expBar.setValue(this._blessData.bless, this._blessData.maxBless);
            this.updatePos();
            this.updateTimeText();
            return;
        }// end function

        private function updatePos() : void
        {
            this._btnOK.y = this._desc.y + this._desc.textHeight + 10;
            this._btnCancel.y = this._desc.y + this._desc.textHeight + 10;
            this.setSize(320, this._btnCancel.y + this._btnCancel.height + 10);
            return;
        }// end function

        private function updateTimeText() : void
        {
            if (this._blessData.blessClear)
            {
                if (this._blessData.bless > 0)
                {
                    this.updateTime();
                }
                else
                {
                    this._leftTime.setLeftTime(0);
                }
            }
            else
            {
                this._leftTime.setLeftTime(0);
            }
            return;
        }// end function

        private function onSecViewTimeChangeHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data as int;
            if (_loc_2 == 0)
            {
                this._expBar.setValue(0, this._blessData.maxBless);
                this._leftTime.stop();
            }
            return;
        }// end function

        public function wiggle() : void
        {
            var timeLite:TimelineLite;
            var x:* = this.x;
            var y:* = this.y;
            timeLite = new TimelineLite();
            timeLite.append(new TweenLite(this, 0.02, {x:x - 7, y:y}));
            timeLite.append(new TweenLite(this, 0.02, {x:x, y:y + 5}));
            timeLite.append(new TweenLite(this, 0.02, {x:x + 7, y:y}));
            timeLite.append(new TweenLite(this, 0.02, {x:x, y:y - 5}));
            timeLite.append(new TweenLite(this, 0.02, {x:x - 7, y:y}));
            timeLite.append(new TweenLite(this, 0.02, {x:x, y:y + 5}));
            timeLite.append(new TweenLite(this, 0.02, {x:x + 7, y:y}));
            timeLite.append(new TweenLite(this, 0.02, {x:x, y:y - 5}));
            timeLite.append(new TweenLite(this, 0.02, {x:x - 7, y:y}));
            timeLite.append(new TweenLite(this, 0.02, {x:x, y:y + 5}));
            timeLite.append(new TweenLite(this, 0.02, {x:x + 7, y:y}));
            timeLite.append(new TweenLite(this, 0.02, {x:x, y:y - 5}));
            timeLite.append(new TweenLite(this, 0.02, {x:x, y:y, onComplete:function () : void
            {
                timeLite.stop();
                timeLite.kill();
                timeLite = null;
                return;
            }// end function
            }));
            timeLite.play();
            return;
        }// end function

        override protected function addCloseButton() : void
        {
            return;
        }// end function

        private function updateTime() : void
        {
            var _loc_1:* = this._blessData.leftSeconds;
            if (_loc_1 > 3600)
            {
                this._leftTime.setParse(Language.getString(30055));
            }
            else if (_loc_1 < 3600)
            {
                this._leftTime.setParse(Language.getString(30056));
            }
            this._leftTime.setLeftTime(_loc_1);
            return;
        }// end function

        public static function get instance() : BlessClearWin
        {
            if (_instance == null)
            {
                _instance = new BlessClearWin;
            }
            return _instance;
        }// end function

        public static function isViewShow() : Boolean
        {
            return _instance && !_instance.isHide;
        }// end function

        public static function hasInstance() : Boolean
        {
            return _instance != null;
        }// end function

    }
}
